Skip to content

The rubygem partial displays the latest release date #4476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

heyapricot
Copy link

@heyapricot heyapricot commented Feb 20, 2024

This PR closes #2993. Let me know what you think!
Update: It closes #4470 as well

Copy link
Member

@simi simi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @heyapricot! Thanks for opening this PR. The overall idea seems fine to me. But the implementation would need few tweaks. Feel free to ping me if help is needed.


current screenshot

image

@@ -3,9 +3,10 @@ class SearchesController < ApplicationController

def show
return unless params[:query].is_a?(String)
@error_msg, @gems = ElasticSearcher.new(params[:query], page: @page).search
@error_msg, @elastic_results = ElasticSearcher.new(params[:query], page: @page).search
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this change is needed? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was me circumventing an issue to get a working proof of concept 😬

@gems originally is assigned a collection of Hash-like objects like this:

<Searchkick::HashWrapper _id="15494" _index="rubygems-development_20240219203755949" _score=248.40211 _type="_doc" description="Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration." downloads=496344261 id="15494" name="rails" summary="Full-stack web application framework." version="7.1.3">

I couldn't figure out how to add the latest_release_date property to the HashWrapper (Took a look here for example)

What I did instead was map the id's from the search result collection, run a new query and use the actual Rubygem objects instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, AFAIK you can use version attribute on returned search result.

@@ -161,6 +161,10 @@ def show_all_versions_link?(rubygem)
rubygem.versions_count > 5 || rubygem.yanked_versions?
end

def latest_release_date(rubygem)
(rubygem.latest_version || rubygem.versions&.last)&.built_at&.strftime("%B %d, %Y")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any case where rubygem.latest_version is nil (or false) but rubygem.versions.last is not? Also created_at should be used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran Rubygem.left_outer_joins(:versions).where(versions: { id: nil }) and it returned 79 results. All of them had the indexed property set to false (Not sure if that affects the search result eligibility).

I followed the pattern from this method:

(rubygem.latest_version || rubygem.versions.last)&.number

Copy link
Author

@heyapricot heyapricot Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up removing the latest_release_date method and using version_date_tag instead

<%= latest_version_number(rubygem) %>
</span>
<span class="gems__gem__latest__release__date">
<%= "released #{latest_release_date(rubygem)}" %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

released should be moved into config/locales/en.yml. Would it be possible to reuse version_date_tag from VersionsHelper?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure what to do with config/locales/en.yml to get the "released" text displayed.
Took a look at

"- #{nice_date_for(version.authored_at)}"

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.35%. Comparing base (0f9f5a0) to head (d0f2203).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4476      +/-   ##
==========================================
- Coverage   97.12%   94.35%   -2.78%     
==========================================
  Files         456      456              
  Lines        9470     9532      +62     
==========================================
- Hits         9198     8994     -204     
- Misses        272      538     +266     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@heyapricot heyapricot force-pushed the add-latest-release-date-to-search-index branch from d7c5d86 to 3941c33 Compare February 22, 2024 03:46
</span>
<span class="gems__gem__latest__release__date">
<%= version_date_tag(rubygem.latest_version) %>
</span>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an acceptable appearance?
Screenshot 2024-02-21 at 21 40 49

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@heyapricot heyapricot requested a review from simi February 22, 2024 03:54
@heyapricot heyapricot force-pushed the add-latest-release-date-to-search-index branch 2 times, most recently from be24725 to 82f3095 Compare February 26, 2024 02:17
@heyapricot
Copy link
Author

@simi Submitted a different and hopefully simpler approach.
Noticed that

has an updated entry so i decided to use that to display the release date when delivering search results. Previously you suggested using created_at but I wanted to show the approach before modifying the search_data method

I included a helper method latest_release_date. If the rubygem partial receives a searchkick object it will use the updated property of the result hash and return a <small> tag with the gem__version__date class.
If the rubygem partial receives a Rubygem object, it will use the version_date_tag helper method you suggested which also returns a <small> tag with the gem__version__date class.

Let me know what you think. Thanks!

@heyapricot heyapricot force-pushed the add-latest-release-date-to-search-index branch from 82f3095 to e7b9799 Compare May 8, 2024 18:56
@simi
Copy link
Member

simi commented Jun 13, 2024

Hello again @heyapricot and sorry for long delay on this review. I did some quick testing and it looks good. The only problem I have noticed is for pre-relase gems only latest_version is nil and that way no date is present, but version is displayed. Any idea what to do in this case? Show latest pre-version date? Maybe the easiest would be to follow logic from latest_version_number helper.

@heyapricot
Copy link
Author

Apologies for missing this message. Just caught it on my notifications while searching for other stuff.

I'll follow the recommendation of checking the other method's logic and will try to work on this over the weekend

@simi
Copy link
Member

simi commented Oct 23, 2024

Happy to review once ready @heyapricot!

@heyapricot heyapricot force-pushed the add-latest-release-date-to-search-index branch 3 times, most recently from e1041ca to 81b2d90 Compare October 27, 2024 20:00
@heyapricot
Copy link
Author

Hello again @heyapricot and sorry for long delay on this review. I did some quick testing and it looks good. The only problem I have noticed is for pre-relase gems only latest_version is nil and that way no date is present, but version is displayed. Any idea what to do in this case? Show latest pre-version date? Maybe the easiest would be to follow logic from latest_version_number helper.

@simi Comment addressed! Here is a brief demo

@simi
Copy link
Member

simi commented Jun 1, 2025

@heyapricot sorry for the delay. It looks good. Would you mind to rebase and fix tests?

@heyapricot
Copy link
Author

@simi On it. Currently traveling. I'll try to get it done by the end of next week

@simi
Copy link
Member

simi commented Jun 5, 2025

@heyapricot no rush and enjoy your travels.

@heyapricot heyapricot force-pushed the add-latest-release-date-to-search-index branch from 81b2d90 to d0f2203 Compare June 13, 2025 14:04
@heyapricot
Copy link
Author

@simi I've rebased.

Running bin/rails test:all I'm seeing ~50 failures when running on the master branch. I also see some intermittent tests.
Here are the logs when running on master.

rubygems_test_all_1.txt
rubygems_test_all_2.txt
rubygems_test_all_3.txt

These are the logs when I ran the tests in the add-latest-release-date-to-search-index branch:
rubygems_test_all_add_latest_release_date.txt

Not really sure how to proceed. Can't pinpoint to a test that's failing specifically because of the changes

@simi
Copy link
Member

simi commented Jun 13, 2025

@heyapricot you can check tests should be passing on main branch https://github.com/rubygems/rubygems.org/actions/workflows/test.yml?query=branch%3Amaster.

But no worries, I'll check. Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Add date of last release to search results page Search Responses Should Show The Date Of The Most Recent Gem Version
2 participants